﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Main_ServiceInvoice_TdsReportSetting : System.Web.UI.Page
{
    Datautility DU = new Datautility();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtFirmName.Enabled = false;
            txtInformation.Enabled = false;
            txtSubject.Enabled = false;
            txtNote.Enabled = false;
            FillTextbox();
        }
    }

    protected void FillTextbox()
    {
        string strsql = "select * from IVC_TDSMANAGEMENT_REPORTSETTING";
        DataTable dt = DU.getdata(strsql);
        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["FIRMNAME"].ToString() != string.Empty)
            {
                txtFirmName.Text = dt.Rows[0]["FIRMNAME"].ToString();
                hidFirmName.Value = dt.Rows[0]["FIRMNAME"].ToString();
            }
            if (dt.Rows[0]["ID"].ToString() != string.Empty)
            {
                hidID.Value = dt.Rows[0]["ID"].ToString();
            }
            if (dt.Rows[0]["FIRMNAMEYN"].ToString() != string.Empty)
            {
                if (Convert.ToBoolean(dt.Rows[0]["FIRMNAMEYN"].ToString()) == true)
                {
                    chkFirmName.Checked = true;
                    txtFirmName.Enabled = true;
                }
            }
            if (dt.Rows[0]["INFORMATION"].ToString() != string.Empty)
            {
                txtInformation.Text = dt.Rows[0]["INFORMATION"].ToString();
                hidInformation.Value = dt.Rows[0]["INFORMATION"].ToString();
            }
            if (dt.Rows[0]["INFORMATIONYN"].ToString() != string.Empty)
            {
                if (Convert.ToBoolean(dt.Rows[0]["INFORMATIONYN"].ToString()) == true)
                {
                    ChkInformation.Checked = true;
                    txtInformation.Enabled = true;
                }
            }
            if (dt.Rows[0]["SUBJECT"].ToString() != string.Empty)
            {
                txtSubject.Text = dt.Rows[0]["SUBJECT"].ToString();
                hidSubject.Value = dt.Rows[0]["SUBJECT"].ToString();
            }
            if (dt.Rows[0]["SUBJECTYN"].ToString() != string.Empty)
            {
                if (Convert.ToBoolean(dt.Rows[0]["SUBJECTYN"].ToString()) == true)
                {
                    chkSubject.Checked = true;
                    txtSubject.Enabled = true;
                }
            }
            if (dt.Rows[0]["NOTE"].ToString() != string.Empty)
            {
                txtNote.Text = dt.Rows[0]["NOTE"].ToString();
                hidNote.Value = dt.Rows[0]["NOTE"].ToString();
            }
            if (dt.Rows[0]["NOTEYN"].ToString() != string.Empty)
            {
                if (Convert.ToBoolean(dt.Rows[0]["NOTEYN"].ToString()) == true)
                {
                    chkNote.Checked = true;
                    txtNote.Enabled = true;
                }
            }
            if (dt.Rows[0]["PRINTLOGOYN"].ToString() != string.Empty)
            {
                if (Convert.ToBoolean(dt.Rows[0]["PRINTLOGOYN"].ToString()) == true)
                {
                    chkPrintLogo.Checked = true;
                }
            }
        }

    }
    protected void chkFirmName_CheckedChanged(object sender, EventArgs e)
    {
        if (txtFirmName.Enabled == false)
        {
            txtFirmName.Enabled = true;
        }
        else
        {
            txtFirmName.Enabled = false;
        }
    }
    protected void ChkInformation_CheckedChanged(object sender, EventArgs e)
    {
        if (txtInformation.Enabled == false)
        {
            txtInformation.Enabled = true;
        }
        else
        {
            txtInformation.Enabled = false;
        }
    }
    protected void chkSubject_CheckedChanged(object sender, EventArgs e)
    {
        if (txtSubject.Enabled == false)
        {
            txtSubject.Enabled = true;
        }
        else
        {
            txtSubject.Enabled = false;
        }
    }
    protected void chkNote_CheckedChanged(object sender, EventArgs e)
    {
        if (txtNote.Enabled == false)
        {
            txtNote.Enabled = true;
        }
        else
        {
            txtNote.Enabled = false;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string firmname = "";
        string information = "";
        string subject = "";
        string note = "";
        if (chkFirmName.Checked == true)
        {
          firmname=txtFirmName.Text.Trim();
        }
        else
        {
          firmname=hidFirmName.Value.ToString();
        }
        if (ChkInformation.Checked == true)
        {
            information = txtInformation.Text.Trim();
        }
        else
        {
            information = hidInformation.Value.ToString();
        }
        if (chkSubject.Checked == true)
        {
            subject = txtSubject.Text.Trim();
        }
        else
        {
            subject = hidSubject.Value.ToString();
        }
        if (ChkInformation.Checked == true)
        {
            note = txtNote.Text.Trim();
        }
        else
        {
            note = hidNote.Value.ToString();
        }
        SqlParameter[] sqlparam = {
                                 new SqlParameter("@ID",hidID.Value.ToString()),
                                 new SqlParameter("@FIRMNAME",firmname),
                                 new SqlParameter("@FIRMNAMEYN",chkFirmName.Checked),
                                 new SqlParameter("@INFORMATION",information),
                                 new SqlParameter("@INFORMATIONYN",ChkInformation.Checked),
                                 new SqlParameter("@PRINTLOGOYN",chkPrintLogo.Checked),
                                 new SqlParameter("@SUBJECT",subject),
                                 new SqlParameter("@SUBJECTYN",chkSubject.Checked),
                                 new SqlParameter("@NOTE",note),
                                 new SqlParameter("@NOTEYN",chkNote.Checked)
                                };
      int id=  DU.executeprocedure("USP_IVC_SaveTDSReportSetting", sqlparam);
      if (id > 0)
      {
          this.Page.RegisterClientScriptBlock("A", "<script type='text/javascript' language='javascript'>window.close();</script>");
      }
    }
    protected void btnClose_Click(object sender, EventArgs e)
    {
        this.Page.RegisterClientScriptBlock("A", "<script type='text/javascript' language='javascript'>window.close();</script>");
    }
}
